//
//  BankSelectViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-5-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BankSelectViewController.h"

@interface BankSelectViewController ()

@end

@implementation BankSelectViewController


@synthesize bankList=_bankList;
@synthesize bankTableView=_bankTableView;
@synthesize delegate=_delegate;

-(void)dealloc{

    [_bankTableView release];
    [_bankList release];
    _delegate=nil;
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self changeBackNavItem];
    
    [backItemButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
    
    NSArray *array=[NSArray arrayWithObjects:@"中国银行",@"招商银行",@"建设银行",@"农业银行",@"工商银行", nil];
    self.bankList=array;
    // Do any additional setup after loading the view from its nib.
}

-(void)cancel:(UIButton *)btn{

    if (_delegate&&[_delegate respondsToSelector:@selector(cancelSelectBankViewController:)]) {
        [_delegate cancelSelectBankViewController:self];
    }
    
    [self.navigationController popViewControllerAnimated: YES];
}


-(void)setBankList:(NSArray *)bankList{

    if ([_bankList isEqualToArray:bankList]) {
        return;
    }
    
    [_bankList release];
    _bankList=[bankList retain];
    [_bankTableView reloadData];
}
#pragma mark UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [_bankList count];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellString=@"Bank list";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellString];
    if (!cell) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString] autorelease];
        cell.backgroundColor=[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.4f];
        cell.textLabel.backgroundColor=[UIColor clearColor];
    }
    cell.textLabel.text=[_bankList objectAtIndex:indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (_delegate &&[_delegate respondsToSelector:@selector(selectBackViewController:selectText:)]) {
        [_delegate selectBackViewController:self selectText:[_bankList objectAtIndex:indexPath.row]];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
